package com.cn.controller;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.entity.TbSalary;
import com.cn.service.salary.TbSalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author qingtian
 * @create 2021-06-03 20:26
 * @
 */
@Controller
@RequestMapping("/salary")
public class TbSalaryController {
    @Autowired
    private TbSalaryService tbSalaryService;

    @RequestMapping("/salaryPage")
    public String salaryList(Model model, @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                             @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,String name,String idCard) {
        Page<TbSalary> page = new Page<>(pageNum,pageSize);

        Page<TbSalary> salaryPage = tbSalaryService.selectAll(page,name,idCard);
        model.addAttribute("salaryPage", salaryPage);
        model.addAttribute("name",name);
        model.addAttribute("idCard",idCard);
        return "/salaryList/saved_resource";
    }

    @RequestMapping("/findAddSalary")
    public String findAddSalary() {
        return "/addSalary/saved_resource";
    }

    @RequestMapping("/selectById")
    public String selectById(Long id,Model model) {
        TbSalary tbSalary = tbSalaryService.selectById(id);
        model.addAttribute("salary",tbSalary);
        return "/updateSalary/saved_resource";
    }

//    @ResponseBody
//    @RequestMapping("/selectByIdCardAndPayCard")
//    public String selectByIdCardAndPayCard(Model model) {
//        List<TbSalary> salaryList = tbSalaryService.selectByIdCardAndPayCard("412724180000001511", "62258837171508232");
//        model.addAttribute("1",salaryList);
//        return salaryList.toString();
//    }

    @RequestMapping("/updateSalary")
    public String updateSalary(TbSalary tbSalary){
        System.out.println(tbSalary);
        int i = tbSalaryService.updateSalary(tbSalary);
        return "redirect:/salary/salaryPage";
    }

}
